home *** CD-ROM | disk | FTP | other *** search
/ Zoom 2 / Zoom - Release 2 (1996)(Active Software)[!].iso / programming / amiga / visualarts / source / clipboard / clipboard.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-02  |  7.0 KB  |  274 lines

  1. /* ******************************************************************** */
  2. /* C code generated by:                            */
  3. /* Visual Arts Version 2.1                        */
  4. /* Copyright 1994-95 Danny Y. Wong  All rights reserved            */
  5. /* Calgary, Alberta (CANADA)                                    */
  6. /* Partial of the code is copyright by Jaba Development            */
  7. /* ******************************************************************** */
  8.  
  9. #include <VisualArts.h>
  10. #include <clib/VisualArts_protos.h>
  11.  
  12. #define ID_write                                      0
  13. #define ID_quit                                       1
  14. #define ID_entry                                      2
  15. #define ID_device                                     3
  16. #define ID_Display                                    4
  17.  
  18. #define ClipBoardNumGads                        5
  19.  
  20. #include "ClipBoard_func.c" 
  21.  
  22. int writeObj(struct VAobject VAObject);
  23. int quitObj(struct VAobject VAObject);
  24. int entryObj(struct VAobject VAObject);
  25. int deviceObj(struct VAobject VAObject);
  26.  
  27. int GetPubScreen(void);
  28. void ClosePubScreen(void);
  29. int OpenClipBoardWindow(char windtitle[]);
  30. void CloseClipBoardWindow(void);
  31. int ClipBoardHandler(void);
  32. int ClipBoardMainHandler(void);
  33. void DrawClipBoardObjs(void);
  34. int main(int argc, char *argv[]);
  35.  
  36. UBYTE                *PubScrName = "Workbench";
  37. struct DrawInfo            *ScrDrawInfo = NULL;
  38. APTR                 VisualInfo = NULL;
  39. struct Screen            *Scr = NULL;
  40. struct Window            *ClipBoardWnd = NULL;
  41. struct Gadget            *ClipBoardGList = NULL;
  42. struct Gadget            *ClipBoardGadgets[ClipBoardNumGads];
  43. struct IntuiMessage         ClipBoardMsg;
  44. UWORD                 ClipBoardLeft = 115;
  45. UWORD                 ClipBoardTop = 47;
  46. UWORD                 ClipBoardWidth = 368;
  47. UWORD                 ClipBoardHeight = 62;
  48.  
  49. /* stringinfo for WB 1.x style string/integer gadgets */
  50.  
  51. struct StringExtend            ClipBoardStrExt;    /* Extend String Gadget */
  52. struct TextAttr topaz8 = { (STRPTR)"topaz.font", 8, 0x00, 0x01 };
  53. struct TextAttr topaz800 = { (STRPTR)"topaz.font", 8, 0x00, 0x00 };
  54.  
  55. UBYTE *DevicesLabels[] = {
  56.     (UBYTE *)"0", 
  57.     (UBYTE *)"1", 
  58.     (UBYTE *)"2", 
  59.     (UBYTE *)"3", 
  60.     (UBYTE *)"4", 
  61.     (UBYTE *)"5", 
  62.     (UBYTE *)"6", 
  63.     (UBYTE *)"7", 
  64.     (UBYTE *)"8", 
  65.     (UBYTE *)"9", 
  66.     NULL
  67. };
  68.  
  69. WORD ClipBoardGadTypes[] = {
  70.     BUTTON_KIND,
  71.     BUTTON_KIND,
  72.     STRING_KIND,
  73.     CYCLE_KIND,
  74.     TEXT_KIND,
  75. };
  76.  
  77. struct NewGadget ClipBoardNGads[] = {
  78.     210, 34, 56, 13, (UBYTE *)"Write",&topaz800, ID_write, PLACETEXT_IN, NULL, (APTR)writeObj,
  79.     300, 34, 56, 13, (UBYTE *)"Quit",&topaz800, ID_quit, PLACETEXT_IN, NULL, (APTR)quitObj,
  80.     81, 19, 275, 13, (UBYTE *)"Entry", &topaz800, ID_entry, PLACETEXT_LEFT, NULL, (APTR)entryObj,
  81.     81, 34, 94, 13, (UBYTE *)"Device", &topaz800, ID_device, PLACETEXT_LEFT, NULL, (APTR)deviceObj,
  82.     81, 2, 275, 15, (UBYTE *)"ClipBoard", &topaz800, ID_Display, PLACETEXT_LEFT, NULL, NULL,
  83. };
  84.  
  85. ULONG ClipBoardNTags[] = {
  86.     TAG_DONE,
  87.     TAG_DONE,
  88.     (GTST_String), (ULONG)"Visual Arts", GTST_MaxChars, 40, (STRINGA_Justification), GACT_STRINGLEFT, TAG_DONE,
  89.     (GTCY_Labels), (ULONG)&DevicesLabels[0], (GTCY_Active), 0, TAG_DONE,
  90.     (GTTX_Text),(ULONG)"", (GTTX_Border), TRUE, TAG_DONE,
  91. };
  92.  
  93.  
  94. int GetPubScreen(void)
  95. {
  96.   if (!(Scr = LockPubScreen(PubScrName)))
  97.     return(1L);
  98.  
  99.   if (!(VisualInfo = GetVisualInfo(Scr, TAG_DONE)))
  100.     return(2L);
  101.  
  102.   if (!(ScrDrawInfo = GetScreenDrawInfo(Scr)))
  103.     return(3L);
  104.   return(0L);
  105. }
  106.  
  107. void ClosePubScreen(void)
  108. {
  109.   if (VisualInfo)
  110.     FreeVisualInfo(VisualInfo);
  111.   if (Scr)
  112.     UnlockPubScreen(NULL,  Scr);
  113.   if (ScrDrawInfo)
  114.     FreeScreenDrawInfo(Scr,  ScrDrawInfo);
  115. }
  116.  
  117. int OpenClipBoardWindow(char windtitle[80])
  118. {
  119.   struct NewGadget    NewGad;
  120.   struct Gadget       *Gad;
  121.   register UWORD i, j;
  122.   UWORD offsetx = Scr->WBorLeft;
  123.   UWORD offsety = Scr->WBorTop + Scr->Font->ta_YSize + 1;
  124.  
  125.  
  126.   ClipBoardStrExt.Font = NULL;
  127.   ClipBoardStrExt.Pens[0] = 1;
  128.   ClipBoardStrExt.Pens[1] = 0;
  129.   ClipBoardStrExt.ActivePens[0] = 2;
  130.   ClipBoardStrExt.ActivePens[1] = 0;
  131.   ClipBoardStrExt.InitialModes  = 0;
  132.   ClipBoardStrExt.EditHook = NULL;
  133.   ClipBoardStrExt.WorkBuffer = NULL;
  134.  
  135.   if (!(Gad = CreateContext(&ClipBoardGList)))
  136.       return(1L);
  137.  
  138.   for (i=0, j=0; i < ClipBoardNumGads; i++)
  139.   {
  140.     CopyMem((char *)&ClipBoardNGads[i], (char *)&NewGad, (long)sizeof(struct NewGadget));
  141.  
  142.     NewGad.ng_VisualInfo = VisualInfo;
  143.     NewGad.ng_LeftEdge += offsetx;
  144.     NewGad.ng_TopEdge  += offsety;
  145.  
  146.     ClipBoardGadgets[i] = Gad = CreateGadgetA((ULONG)ClipBoardGadTypes[i], Gad, &NewGad,
  147.     (struct TagItem *)&ClipBoardNTags[j]);
  148.     if (ClipBoardGadTypes[i] == STRING_KIND || ClipBoardGadTypes[i] == INTEGER_KIND)
  149.     {
  150.     ClipBoardGadgets[i]->Flags |= GFLG_STRINGEXTEND;
  151.     ((struct StringInfo *)ClipBoardGadgets[i]->SpecialInfo)->Extension = &ClipBoardStrExt;
  152.     }
  153.     while (ClipBoardNTags[j])
  154.         j +=2;
  155.     j++;
  156.     if (!Gad)
  157.        return(2L);
  158.   }
  159.   if (!(ClipBoardWnd = OpenWindowTags(NULL,
  160.       WA_Left,    ClipBoardLeft,
  161.       WA_Top,     ClipBoardTop,
  162.       WA_Width,    ClipBoardWidth,
  163.       WA_Height,    ClipBoardHeight + kWindowOffSetY,
  164.       WA_NewLookMenus, TRUE,
  165.       WA_IDCMP,    IDCMP_CLOSEWINDOW |  IDCMP_NEWSIZE | IDCMP_GADGETUP ,
  166.       WA_Flags,    WFLG_CLOSEGADGET | WFLG_DEPTHGADGET  |  WFLG_SMART_REFRESH | 
  167.              WFLG_RMBTRAP |  WFLG_ACTIVATE | 
  168.              WFLG_DRAGBAR ,
  169.       WA_Gadgets,    ClipBoardGList,
  170.       WA_Title,    windtitle,
  171.       WA_ScreenTitle,    "Visual Arts V2.2 Copyright 1994-95 Danny Y. Wong  All Rights Reserved.",
  172.       WA_PubScreen,    Scr,
  173.       WA_MinWidth,    160,
  174.       WA_MinHeight,    50,
  175.       WA_MaxWidth,    640,
  176.       WA_MaxHeight,    200,
  177.       TAG_DONE)))
  178.           return(3L);
  179.  
  180.   CreateClipBoardLists();
  181.   GT_RefreshWindow(ClipBoardWnd, NULL);
  182.   RefreshGadgets(ClipBoardGadgets[0], ClipBoardWnd, NULL);
  183.   return(0L);
  184. }
  185.  
  186. void CloseClipBoardWindow(void)
  187. {
  188.   if (ClipBoardWnd)
  189.     CloseWindow(ClipBoardWnd);
  190.   if (ClipBoardGList)
  191.     FreeGadgets(ClipBoardGList);
  192. }
  193.  
  194. int ClipBoardHandler(void)
  195. {
  196.   struct IntuiMessage    *msg;
  197.   struct VAobject    VAObject;
  198.   int running    = 1;
  199.   int (*func)(struct VAobject VAObject);
  200.   ULONG class;
  201.   UWORD code;
  202.  
  203.   while (msg=GT_GetIMsg(ClipBoardWnd->UserPort))
  204.   {
  205.     CopyMem((char *)msg, (char *)&ClipBoardMsg, (long)sizeof(struct IntuiMessage));
  206.     class = msg->Class;
  207.     code  = msg->Code;
  208.  
  209.     VAObject.va_Window = (struct Window *)ClipBoardWnd;
  210.     VAObject.va_Gadget = (struct Gadget *)msg->IAddress;
  211.     VAObject.va_IntuiMsg = (struct IntuiMessage *)msg;
  212.     VAObject.va_Flags = 0;
  213.     VAObject.va_UserData = 0;
  214.  
  215.     GT_ReplyIMsg(msg);
  216.     switch(class)
  217.     {
  218.  
  219.       case IDCMP_NEWSIZE:
  220.        break;
  221.  
  222.       case IDCMP_CLOSEWINDOW:
  223.          return(0);
  224.          break;
  225.  
  226.       case IDCMP_GADGETUP:
  227.         func = (void *)((struct Gadget *)ClipBoardMsg.IAddress)->UserData;
  228.         if (func != NULL)
  229.           running =  func(VAObject);
  230.         break;
  231.  
  232.     }
  233.   }
  234.   return(running);
  235. }
  236.  
  237. int ClipBoardMainHandler(void)
  238. {
  239.   int running = 1;
  240.   ULONG windsig, signals;
  241.  
  242.   windsig = 1L << ClipBoardWnd->UserPort->mp_SigBit;
  243.  
  244.   while (running == 1)
  245.   {
  246.     signals = Wait( windsig );
  247.     if (signals & windsig)
  248.     {
  249.       running = ClipBoardHandler();
  250.     }
  251.   }
  252.   return(running);
  253. }
  254.  
  255. int main(int argc, char *argv[])
  256. {
  257.   int rc;
  258.  
  259.   if (!(GetPubScreen()))
  260.   {
  261.     for (rc=0; rc < 1; rc++)
  262.       ClipBoardLists[rc]=GetNewList();
  263.     if (!(OpenClipBoardWindow("ClipBoard Demo")))
  264.     {
  265.       rc = ClipBoardMainHandler();
  266.       CloseClipBoardWindow();
  267.     }
  268.     for (rc=0; rc < 1; rc++)
  269.       FreeList(ClipBoardLists[rc]);
  270.     ClosePubScreen();
  271.   }
  272.   return(0L);
  273. }
  274.